package es.app.acciones;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.log4j.Logger;
import org.apache.log4j.MDC;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;

public class InicioAction extends DispatchAction{
	
	private static final Logger log = Logger.getLogger(InicioAction.class);
	
	public ActionForward inicio(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) {
		HttpSession sesion = request.getSession(false);
		sesion.invalidate();
		
		DateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmssSSS");
		Date date = new Date();
		String idSession = dateFormat.format(date);
		MDC.put("idSesion", "00000000000000000");
		log.debug("Se ha invalidado la sesion y se muestra la pagina de login");
		log.debug("Se crea el identificador de sesion: "+idSession);
		MDC.put("idSesion", idSession);
		sesion = request.getSession(true);
		sesion.setAttribute("idSesion", idSession);
		
		return mapping.findForward("login");
	}

}
